//
//  SearchResultCell.m
//  YaoHeAPP
//
//  Created by xyh on 16/7/27.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "SearchResultCell.h"
#import "UILabel+StringFrame.h"
#import "SearchListItemModel.h"
@interface SearchResultCell ()

@property(nonatomic,strong)UIView *topView;//顶部白色
@property(nonatomic,strong)UIView *buttomView;//底部灰色
@property(nonatomic,strong)UILabel *nameLable;//名字
@property(nonatomic,strong)UILabel *jineLable;//金额
@property(nonatomic,strong)UILabel *beizhuLable;//备注
@end

@implementation SearchResultCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.backgroundColor = [UIColor clearColor];
        
        _topView = [[UIView alloc]initWithFrame:CGRectMake(0, 0,SCREEN_WIDTH,40)];
        _topView.backgroundColor = [UIColor whiteColor];
        [self addSubview:_topView];
        
        _nameLable = [[UILabel alloc] initWithFrame:CGRectMake(10, 5, 100, 30)];
        _nameLable.font = Font(13);
        _nameLable.textAlignment = NSTextAlignmentLeft;
        [_topView addSubview:_nameLable];
        
       
        _jineLable = [[UILabel alloc]initWithFrame:CGRectMake(10+100+5, 5, SCREEN_WIDTH-(10+100+5)-10, 30)];
        _jineLable.textAlignment=NSTextAlignmentRight;
        _jineLable.font = Font(13);
        _jineLable.textColor = RGBCOLOR(251, 87, 60);
        [_topView addSubview:_jineLable];

        
        _buttomView = [[UIView alloc]initWithFrame:CGRectMake(0, 40, SCREEN_WIDTH,50)];
        _buttomView.backgroundColor = RGBCOLOR(249, 249, 249);
        [self addSubview:_buttomView];
 
        
        _beizhuLable = [[UILabel alloc]init];
        _beizhuLable.textAlignment = NSTextAlignmentLeft;
        _beizhuLable.font = Font(12);
        _beizhuLable.numberOfLines = 0;
        _beizhuLable.textColor=RGBCOLOR(153, 153, 153);
        [_buttomView addSubview:_beizhuLable];
        
        
        UIButton *Need_Btn = [UIButton buttonWithType:UIButtonTypeCustom];
        Need_Btn.layer.masksToBounds = YES;
        Need_Btn.layer.cornerRadius = 15;
        Need_Btn.backgroundColor = RGBCOLOR(251, 87, 60);
        [Need_Btn addTarget:self action:@selector(NeedBtn) forControlEvents:UIControlEventTouchUpInside];
        [Need_Btn setTitle:@"我要买" forState:UIControlStateNormal];
        Need_Btn.titleLabel.font = Font(13);
        [Need_Btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_buttomView addSubview:Need_Btn];
        Need_Btn.frame = CGRectMake(SCREEN_WIDTH-10-80, 10, 80, 30);
        
        
        UIButton *imageButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [imageButton setBackgroundImage:[UIImage imageNamed:@"zoushiimage"] forState:UIControlStateNormal];
        [imageButton addTarget:self action:@selector(imageButtonBtn) forControlEvents:UIControlEventTouchUpInside];
        [_buttomView addSubview:imageButton];
        imageButton.frame = CGRectMake(SCREEN_WIDTH-10-80-10-30, 10, 30, 30);
        
         _beizhuLable.frame = CGRectMake(10, 10, SCREEN_WIDTH-10-80-10-30-10-5, 30);
    }
    return self;
}

- (void)setSearchListItemModel:(SearchListItemModel *)searchListItemModel {
    _searchListItemModel = searchListItemModel;
    
    //拼接顶部消息
    NSString *TopnameString = [NSString stringWithFormat:@"%@ %@",searchListItemModel.FactoryName,searchListItemModel.ThickName];
    _nameLable.text = TopnameString;
    CGSize tempSize = [self.nameLable boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, 30)];
    _nameLable.frame=CGRectMake(10, 5,tempSize.width, 30);

    //价格
    NSString *danwei;
    NSInteger danweiUnit=searchListItemModel.Unit.integerValue;
    if (danweiUnit==10) {
        //10:元/吨
        danwei = @"元/吨";
    }else if (danweiUnit==20){
        //20:元/张
        danwei = @"元/张";
    }else if (danweiUnit==30){
        //30:元/公斤
        danwei = @"元/公斤";
    }else if (danweiUnit==40){
        //40:元/支
        danwei = @"元/支";
        
    }
    
    NSString *tmpjineString = [NSString stringWithFormat:@"￥%@%@",searchListItemModel.Price,danwei];
    _jineLable.text = tmpjineString;
    _jineLable.frame = CGRectMake(10+tempSize.width+5, 5, SCREEN_WIDTH-(10+tempSize.width+5)-10, 30);
    _beizhuLable.text = [NSString stringWithFormat:@"备注：%@",searchListItemModel.Remark];
}

//我要买的按钮点击
-(void)NeedBtn{
    if (self.searchResultCellNeedBtnActionBlock) {
        self.searchResultCellNeedBtnActionBlock();
    }
}

//点击统计图按钮
-(void)imageButtonBtn {
    if (self.searchResultCellImageBtnActionBlock) {
        self.searchResultCellImageBtnActionBlock(_searchListItemModel);
    }
}

@end
